<template>
  <van-cell-group inset>
    <van-cell type="digit">
      订单号&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{entrust.id}}
    </van-cell>
    <van-field v-model="entrust.city" label="省份"/>
    <van-field v-model="entrust.province" label="城市"/>
    <van-field v-model="entrust.county" label="县/区"/>
    <van-field v-model="entrust.detailAdd" label="详细地址"/>
    <van-field v-model="entrust.postalCode" type="digit" label="邮政编码"/>
    <van-field v-model="entrust.consigneeName" label="收货人姓名"/>
    <van-field v-model="entrust.consigneePhone" label="发货人电话"/>
    <van-field v-model="entrust.shipperName" label="收货人姓名"/>
    <van-field v-model="entrust.shipperPhone" label="收货人电话"/>
  </van-cell-group>
  <div className="save">
    <van-button type="primary" round @click="onSave">保存更改</van-button>
  </div>
</template>

<script setup>
import {ref} from "vue";
import {GlobalEntrust} from "../config/globalConfig";
import {updateEntrustInfo} from "../api/request";
import {Toast} from "vant";
import route from "../config/route";

let entrust = ref(GlobalEntrust)

const onSave = async () => {
  try {
    let result = await updateEntrustInfo(entrust.value)
    result = result.data
    if (result.statusCode !== 0) {
      Toast.fail(result.message + '---' + result.description);
      return
    }
    Toast.success('保存成功!')
    route.back()
  } catch (err) {
    Toast.fail(err.message)
  }
}

</script>

<style scoped>
.save {
  padding-top: 7%;
  padding-left: 60%;
}
</style>